package anivis.ui;

import java.awt.Container;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Observable;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import anivis.AniVisApp;
import anivis.ui.map.AnimalLayer;
import anivis.ui.timeline.TimelineView;

import com.bbn.openmap.gui.OMComponentPanel;
import com.bbn.openmap.gui.OMToolComponent;

public class AttributeWindow extends OMToolComponent {

    private JFrame frame = null;
    private AnimalLayer animalLayer = null;
    private Controller controller;
    /**
     * Tool interface method. The retrieval tool's interface. This
     * method creates a button that will bring up the BeanPanel.
     * 
     * @return A container that will contain the 'face' of this panel
     *         on the OpenMap ToolPanel.
     */
    public Container getFace() {
        JButton button = null;

        if (getUseAsTool()) {
            button = new JButton(new ImageIcon("share/img/bird.png"));
            button.setBorderPainted(false);
            button.setToolTipText("Open Attribute Windoww");
            button.setMargin(new Insets(0, 0, 0, 0));
            button.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    System.out.println("Opening AttributeView");
                    display();
                }
            });
        }

        return button;
        
    }
    
    /**
     * Get the ActionListener that triggers the LayersPanel. Useful to have to
     * provide an alternative way to bring up the LayersPanel.
     * 
     * @return ActionListener
     */
    private synchronized void display() {
        if (frame == null) {
            frame = new JFrame("Attributes");
            JPanel panel = new AttributeView(AniVisApp.getApplication().getController().getQueryLayer());
            
            frame.add(panel);
            
            frame.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent evt) {
                    frame.setVisible(false);
                }
            });
        
            frame.pack();
        }
        frame.setVisible(true);
    }
}
